<?php

namespace app\api\controller;

use app\common\controller\Api;


class Driver extends Api
{
    protected $noNeedLogin = [];
    protected $noNeedRight = [];

    public function driverApply(){
        $uid = $this->uid;
        $driver = new \app\admin\model\Driver();
        $data = [
            'uid'=>$uid,
            'name'=>input('name'),//姓名
            'card_number'=>input('card_number'),//身份证号
            'age'=>input('age'),//年龄
            'car_id'=>input('car_id'),//车型ID
            'license'=>input('license'),//车牌号
            'card_image1'=>input('card_image1'),//身份证 正面
            'card_image2'=>input('card_image2'),//身份证 背面
            'drive_image'=>input('drive_image'),//驾驶页
            'use_image1'=>input('use_image1'),//行驶证主页
            'use_image2'=>input('use_image2'),//行驶证副页
            'car_image'=>input('car_image'),//车辆照片
            'Insurance'=>input('Insurance'),//保险单
            'freight'=>input('freight'),//货运资格
            'updatetime'=>time(),
            'status'=>1,
        ];
        $info = $driver->field('status')->where(['uid'=>$uid])->find();
        if($info){
            if(in_array($info['status'],['1','2'])){
                $this->ajaxError('当前状态不可提交');
            }
            $info->save($data);
            $this->ajaxSuccess();
        }
        $data['createtime'] = time();
        var_dump($data);die;
        $driver->save($data);
        $this->ajaxSuccess();
    }

    public function applyStatus(){
        $uid = $this->uid;
        $driver = new \app\admin\model\Driver();
        $info = $driver->field('status')->where(['uid'=>$uid])->find();
        $license = $driver->field('license')->where(['uid'=>$uid])->find();

        if ('' ==$license['license'] || null == $license['license']){
            $info['message']='该司机未提交资料申请';
            $info['status']='4';
            $info['status_text']='Status 4';
            $this->ajaxSuccess($info);
        }
        if($info){
            $this->ajaxSuccess($info);
        }else{
            $this->ajaxSuccess(['status'=>0]);
        }

    }

    public function driverLogin(){
        $driver = new \app\admin\model\Driver();
        $name = input("name");//姓名
        $password = input("password");
        $uid = $driver->field('uid')->where(['name'=>$name])->find();
        if ($uid){
            $uid = $driver->field('uid')->where(['name'=>$name])->find();
        }
    }
}
